package com.lmscn.lms.api.model;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;

/**
 * 2016年12月21日17:27:58.
 */
@SuppressWarnings("serial")
public class ArticleCommentCkGood extends Model<ArticleCommentCkGood> {

    public static final ArticleCommentCkGood dao = new ArticleCommentCkGood();

    /**
     * 保存评论点赞
     * @param commentCkGood
     * @param commentId
     * @param studentId
     * @param articleId
     */
    public void saveCkGood(ArticleCommentCkGood commentCkGood,Long commentId,Long studentId,Long articleId){
        commentCkGood.set("comment_id",commentId);
        commentCkGood.set("article_id",articleId);
        commentCkGood.set("student_id",studentId);
        commentCkGood.remove("id").save();
    }

    /**
     * 查找是否对评论点赞
     * @param articleId
     * @param studentId
     * @param commentId
     * @return
     */
    public ArticleCommentCkGood getCommentCkGood(Long articleId,Long studentId,Long commentId){
        return dao.findFirst("select * from t_article_comment_ckgood " +
                "where comment_id =? and article_id=? and student_id =?",commentId,articleId,studentId);

    }
    
    public long getCommentCkGoodNumByID(Long commentId) {
    	String sql = " SELECT count(*) FROM t_article_comment_ckgood t WHERE t.comment_id = ? ";
//    	List<CourseCommentCkGood> goodList = dao.find(sql,commentId);
//    	return goodList.size();
    	
    	return Db.queryLong(sql, commentId);
    }
}
